import { shapeFlags } from '../shared/ShapeFlags'

export const Fragment = Symbol('Fragment')
export const Text = Symbol('Text')

export {
    createVNode as createElementVnode
} 

export function createVNode(type,props?,children?) {
    const vnode = {
        // type 就是App.js的整个对象
        type,
        props,
        key:props && props.key,
        children,
        shapeFlag:getFlags(type),
        el:null,
    }
    // children
    if(typeof children === 'string') {
        // 这个地方是合并修改，先判断vnode的type，然后是vnode的children
        vnode.shapeFlag = vnode.shapeFlag | shapeFlags.TEXT_CHILDREN
    }else if(Array.isArray(children)) {
        vnode.shapeFlag = vnode.shapeFlag | shapeFlags.ARRAY_CHILDREN
    }


    return vnode
}

export function createTextVNode(text) {
    return createVNode(Text,{},text)
}

function getFlags(type) {
    return typeof type === 'string' ? shapeFlags.ELEMENT : shapeFlags.STATEFUL_COMPONENT
}